import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const modules1 = {
  namespaced: true,
  state: {
    username: 'wangjian',
    password: '123456'
  },
  mutations: {
    changeUsername (state) {
      state.username = '网阿金'
    }
  },
  getters: {
    getNewUsername (state) {
      return state.username + '1'
    }
  }
}
export default new Vuex.Store({
  state: {
    username: 'admin',
    password: '123456',
    count: 0
  },
  // 在其他地方调用的时候 this.$store.commit('addCount',5)
  mutations: {
    addCount (state, num) {
      state.count += num
    }
  },
  // 在其他地方调用的时候 this.$store.getters.getAddCount()
  getters: {
    getAddCount (state) {
      return state.count + 5
    },
    getAddCount1 (state, getters) {
      return getters.getAddCount * 2
    }
  },
  actions: {
  },
  modules: {
    modules1: modules1
  }
})
